// ignore_for_file: non_constant_identifier_names, unused_element

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:verse_systems/commom/models/payment_confirm_model.dart';
import 'package:verse_systems/pages/repayment/repayment_control.dart';
import 'package:verse_systems/res/colors.dart';
import 'package:verse_systems/utils/image_utils.dart';
import 'package:verse_systems/widgets/drawer_appbar.dart';
import 'package:verse_systems/widgets/sp_button.dart';

class RepaymentConfirm extends StatefulWidget {
  const RepaymentConfirm({super.key});

  @override
  State<RepaymentConfirm> createState() => _RepaymentConfirmState();
}

class _RepaymentConfirmState extends State<RepaymentConfirm> {
  final control = Get.put(RepaymentControl());
  final state = Get.find<RepaymentControl>().state;

  @override
  void initState() {
    super.initState();
    control.repaymentConfirm();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colours.system_background_color,
        body: GetBuilder<RepaymentControl>(
            init: control,
            builder: (_) {
              return GestureDetector(
                onTap: () {
                  FocusScope.of(context).unfocus();
                },
                child: SizedBox(
                height: MediaQuery.of(context).size.height,
                child: Stack(
                  children: [_confirmUs, _confirmContent],
                ),
              )) ;
            }));
  }

  Widget get _confirmContent {
    return SizedBox(
        child: SingleChildScrollView(
      child: Column(
        children: [
         DrawerAppbar(
            backgroundColor: Colors.transparent,
            color: Colours.app_main_color,
            title: "repayment".tr,
          ),
          _confirmContainer,
          _confirmPressed
        ],
      ),
    ));
  }

  Widget get _confirmPressed {
    return Container(
      margin: EdgeInsets.fromLTRB(0, 204.w, 0, 30.w),
      child: Column(
        children: [
          Text(
            "confirm_pay_name_to_submit".tr,
            style: TextStyle(
              color: Colours.app_main_background_color,
              fontSize: 12.sp,
            ),
          ),
          SizedBox(height: 10.w),
          SizedBox(
              width: 310.w,
              child: SPButton(
                minHeight: 50.w,
                fontSize: 18.sp,
                text: "submitted".tr,
                radius: 25.w,
                textColor: Colours.app_main_color,
                backgroundColor: Colours.app_main_background_color,
                onPressed: control.repayment_confirm,
              ))
        ],
      ),
    );
  }

  Widget get _confirmContainer {
    return Container(
      padding: EdgeInsets.fromLTRB(50.w, 23.w, 50.w, 38.w),
      margin: EdgeInsets.symmetric(
          horizontal: (MediaQuery.of(context).size.width - 330.w) / 2,
          vertical: 5.w),
      width: 330.w,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(10.w)),
          color: Colours.app_main_color,
          boxShadow: [
            BoxShadow(
                color: Colours.stringAnAlphaColor("0xff000000", alpha: 0.08),
                offset: const Offset(0.0, 15.0), //阴影xy轴偏移量
                blurRadius: 25.0, //阴影模糊程度
                spreadRadius: 0.5 //阴影扩散程度
                )
          ]),
      child: Column(
        children: [
          Column(children: _payment_list),
          _real_name_textField
          
          ],

      ),
    );
  }

   Widget get _real_name_textField {
    return  Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      "pay_name".tr,
                      style: TextStyle(
                        color: Colours.app_text_color,
                        fontSize: 14.sp,
                      ),
                    ),
                    Expanded(
                      child: TextField(
                      maxLines: 1,
                      keyboardType: TextInputType.text,
                         controller: control.real_name_control,
                      // controller: control.real_name_control ..text = state.payment!.realName!,
                      textAlign: TextAlign.right, //文本对齐方式
                      style: TextStyle(
                        fontSize: 15.sp,
                        color: Colours.app_black_text_color,
                      ),
                      decoration: InputDecoration(
                          suffixIcon: Icon(
                            Icons.mode_edit_outline,
                            color: Colours.app_line_color,
                            size: 18.w,
                          ),
                          border: InputBorder.none,
                          hintText: "please_enter".tr,
                          counterText: '',
                          hintStyle: TextStyle(
                            fontSize: 15.sp,
                          )),
                      showCursor: true,
                      cursorColor: Colours.app_main_background_color,
                      onChanged: (v) {

                      },
                    ))
                  ],
                ),
                Container(
                  height: 1.w,
                  color: Colours.app_text_line_color,
                ),
              ],
            );
  }

  List<Widget> get _payment_list {
    if (state.payment == null || state.payment!.details == null|| state.payment!.details!.isEmpty) {
      return [Container()];
    }
    return state.payment!.details!.map((PaymentConfirmModelDetails details) {
      return Column(
        children: [
          Container(
            margin: EdgeInsets.symmetric(vertical: 13.w),
            child:  Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                details.key ?? "",
                style: TextStyle(
                  color: Colours.app_text_color,
                  fontSize: 14.sp,
                ),
              ),
              Text(
                details.value ?? "",
                style: TextStyle(
                  color: Colours.app_black_text_color,
                  fontSize: 14.sp,
                ),
              ),
            ],
          ),
          ),
          Container(
            height: 1.w,
            color: Colours.app_text_line_color,
          ),
        ],
      );
    }).toList();
  }

  Widget get _confirmUs {
    return Container(
        height: 300.w,
        decoration: BoxDecoration(
          image: DecorationImage(
              image: ExactAssetImage(ImageUtils.getImgPath("loan_background")),
              fit: BoxFit.fill),
        ));
  }
}
